home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dragpic2 / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1998-04-06  |  5.3 KB  |  168 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   5865
  5.    ClientLeft      =   1275
  6.    ClientTop       =   1530
  7.    ClientWidth     =   3840
  8.    Height          =   6270
  9.    Left            =   1215
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5865
  12.    ScaleWidth      =   3840
  13.    Top             =   1185
  14.    Width           =   3960
  15.    Begin VB.CheckBox chkUseOutline 
  16.       Caption         =   "Use Outline"
  17.       Height          =   255
  18.       Left            =   120
  19.       TabIndex        =   4
  20.       Top             =   120
  21.       Width           =   1455
  22.    End
  23.    Begin VB.PictureBox picMask 
  24.       AutoRedraw      =   -1  'True
  25.       Height          =   1665
  26.       Left            =   3360
  27.       Picture         =   "Form1.frx":0000
  28.       ScaleHeight     =   107
  29.       ScaleMode       =   3  'Pixel
  30.       ScaleWidth      =   91
  31.       TabIndex        =   2
  32.       Top             =   2640
  33.       Visible         =   0   'False
  34.       Width           =   1425
  35.    End
  36.    Begin VB.PictureBox picImage 
  37.       AutoRedraw      =   -1  'True
  38.       Height          =   1665
  39.       Left            =   3360
  40.       Picture         =   "Form1.frx":739E
  41.       ScaleHeight     =   107
  42.       ScaleMode       =   3  'Pixel
  43.       ScaleWidth      =   91
  44.       TabIndex        =   1
  45.       Top             =   840
  46.       Visible         =   0   'False
  47.       Width           =   1425
  48.    End
  49.    Begin VB.PictureBox picBackground 
  50.       AutoRedraw      =   -1  'True
  51.       Height          =   5385
  52.       Left            =   1680
  53.       Picture         =   "Form1.frx":E73C
  54.       ScaleHeight     =   355
  55.       ScaleMode       =   3  'Pixel
  56.       ScaleWidth      =   251
  57.       TabIndex        =   0
  58.       Top             =   1800
  59.       Visible         =   0   'False
  60.       Width           =   3825
  61.    End
  62.    Begin VB.PictureBox picCanvas 
  63.       AutoRedraw      =   -1  'True
  64.       DrawMode        =   6  'Mask Pen Not
  65.       Height          =   5385
  66.       Left            =   0
  67.       ScaleHeight     =   355
  68.       ScaleMode       =   3  'Pixel
  69.       ScaleWidth      =   251
  70.       TabIndex        =   3
  71.       Top             =   480
  72.       Width           =   3825
  73.    End
  74. Attribute VB_Name = "Form1"
  75. Attribute VB_Creatable = False
  76. Attribute VB_Exposed = False
  77. Option Explicit
  78. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
  79. Private Const SRCAND = &H8800C6
  80. Private Const MERGEPAINT = &HBB0226
  81. ' Set false to draw the picture. It's slower.
  82. Private UseOutline As Boolean
  83. ' The canvas's dimensions.
  84. Private CanvasWid As Single
  85. Private CanvasHgt As Single
  86. ' The picture's dimensions.
  87. Private PicWid As Single
  88. Private PicHgt As Single
  89. ' The picture's current position.
  90. Private PicX As Single
  91. Private PicY As Single
  92. ' Are we dragging?
  93. Private Dragging As Boolean
  94. Private OffsetX As Single
  95. Private OffsetY As Single
  96. ' Draw the picture.
  97. Private Sub DrawPic()
  98.     picCanvas.Picture = picBackground.Picture
  99. '    picCanvas.PaintPicture picMask.Picture, _
  100. '        PicX, PicY, PicWid, PicHgt, _
  101. '        0, 0, PicWid, PicHgt, vbMergePaint
  102.     BitBlt picCanvas.hDC, _
  103.         PicX, PicY, PicWid, PicHgt, _
  104.         picMask.hDC, _
  105.         0, 0, MERGEPAINT
  106. '    picCanvas.PaintPicture picImage.Picture, _
  107. '        PicX, PicY, PicWid, PicHgt, _
  108. '        0, 0, PicWid, PicHgt, vbSrcAnd
  109.     BitBlt picCanvas.hDC, _
  110.         PicX, PicY, PicWid, PicHgt, _
  111.         picImage.hDC, _
  112.         0, 0, SRCAND
  113.     picCanvas.Picture = picCanvas.Image
  114. End Sub
  115. ' Draw an outline of the picture.
  116. Private Sub DrawOutline()
  117.     picCanvas.Line _
  118.         (PicX, PicY)-Step(PicWid, PicHgt), , B
  119. End Sub
  120. ' Draw the initial picture.
  121. Private Sub Form_Load()
  122.     CanvasWid = picCanvas.ScaleWidth
  123.     CanvasHgt = picCanvas.ScaleHeight
  124.     PicWid = picImage.ScaleWidth
  125.     PicHgt = picImage.ScaleHeight
  126.     PicX = PicWid
  127.     PicY = PicHgt
  128.     DrawPic
  129. End Sub
  130. ' See if the mouse is over a point corresponding
  131. ' to a black part of the mask.
  132. Private Sub picCanvas_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  133.     OffsetX = PicX - x
  134.     OffsetY = PicY - y
  135.     If picMask.Point(-OffsetX, -OffsetY) <> vbBlack Then Exit Sub
  136.     ' Start dragging.
  137.     UseOutline = (chkUseOutline.Value = vbChecked)
  138.     If UseOutline Then DrawOutline
  139.     Dragging = True
  140. End Sub
  141. ' Drag.
  142. Private Sub picCanvas_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  143.     If Not Dragging Then Exit Sub
  144.     If UseOutline Then DrawOutline
  145.     PicX = x + OffsetX
  146.     If PicX < 0 Then
  147.         PicX = 0
  148.     ElseIf PicX > CanvasWid - PicWid Then
  149.         PicX = CanvasWid - PicWid
  150.     End If
  151.     PicY = y + OffsetY
  152.     If PicY < 0 Then
  153.         PicY = 0
  154.     ElseIf PicY > CanvasHgt - PicHgt Then
  155.         PicY = CanvasHgt - PicHgt
  156.     End If
  157.     If UseOutline Then
  158.         DrawOutline
  159.     Else
  160.         DrawPic
  161.     End If
  162. End Sub
  163. ' Stop dragging.
  164. Private Sub picCanvas_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  165.     If UseOutline Then DrawPic
  166.     Dragging = False
  167. End Sub
  168.